import { queryProductInfo } from '@/api/info'

const productInfo = {
  state: {
    // 产品树形列表
    productTreeList: []
  },
  getters: {
    productTreeList: (state) => state.productTreeList
  },
  mutations: {
    SET_PRODUCT_TREE_LIST: (state, productTreeList) => {
      state.productTreeList = productTreeList
    }
  },
  actions: {
    /** 获取产品树形列表 */
    getProductTreeList({ commit }) {
      const params = {
        // 只显示到3级菜单
        qry_productlevel: 3
      }
      return new Promise((resolve, reject) => {
        queryProductInfo(params)
          .then((res) => {
            if (res.success) {
              commit('SET_PRODUCT_TREE_LIST', res.result.dataList[0].children)
              resolve(res.result)
            } else {
              reject(res.message)
            }
          })
          .catch((err) => {
            reject(err)
          })
      })
    }
  }
}
export default productInfo
